<?
function getEU() {
	global $dbname, $db, $db_selected, $pre;
	
	$sql = "SELECT * from casa_events_updates LIMIT 1";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_assoc($result);
	
	$date    = mySQLToExt($row[EUDate]);
	$content = $row[EUContent];
	$active  = $row[Active];
	
	$returnString = $date.'|'.$content.'|'.$active;
	return $returnString;
}

function saveEU($date,$content,$active) {
	global $dbname, $db, $db_selected, $pre;
	
	$date = extDateToMySQL($date);
	
	$sql = "UPDATE casa_events_updates SET
			EUDate    = '$date',
			EUContent = '$content',
			Active    = '$active'
			WHERE EUID = 1";
	$result = mysql_db_query($dbname,$sql);
}

function getFiles() {
	global $dbname, $db, $db_selected, $pre;
	$fileString = '';
	$sql = "SELECT CU.FID,CU.PID,CU.FileName,CU.FileNotes,CU.FileType,CU.DateUpload,CP.ProgramName,CP.County
		FROM casa_uploads CU
		LEFT JOIN casa_programs CP ON CP.PID = CU.PID
		ORDER BY CP.ProgramName,CU.DateUpload DESC";
	$result = mysql_db_query($dbname,$sql);
	$rows = mysql_num_rows($result);
	
	if ($rows>0) {	
		// Render file table
		$fileString .= '<table class="dataTable" style="width: 100%;">';
		$fileString .= '<tr>';
			$fileString .= '<th style="width: 5%;"></th>';
			$fileString .= '<th style="width: 10%;">Download</th>';
			$fileString .= '<th style="width: 30%;">Program</th>';		
			$fileString .= '<th style="width: 40%;">Notes</th>';
			$fileString .= '<th style="width: 15%;">Date Submitted</th>';
		$fileString .= '</tr>';
		$i=0;
		while ($value = mysql_fetch_assoc($result)) {
			$fID        = $value[FID];
			$program    = $value[ProgramName];
			$county     = $value[County];
			$fileName   = $value[FileName];
			$fileType   = $value[FileType];
			$fileNotes  = '<a href="'.SITE_URL.'/docs/Uploaded Files/'.$fileName.'" title="Download file">'.$fileName.'</a><br />'.$value[FileNotes];
			$dateUpload = mysql_to_date2($value[DateUpload]);
	
			if ($fileType == 'excel') {
				$fileIcon = 'iconExcel.gif'; 
			} elseif ($fileType == 'word') {
				$fileIcon = 'iconWord.gif';
			}
	
			if (($i % 2) > 0) { $class = 'noRowClass'; }
				else { $class = "altRow"; }
			$fileString .= '<tr id="fileRow'.$fID.'" class="'.$class.'">';
			$fileString .= '<td style="text-align: center;"><a href="#" onClick="confirmDelete(\''.$fID.'\',\'uploadedFile\'); return false;"><img src="images/iconDelete.gif" style="border: none;" alt="Delete this file" /></a></td>';
				$fileString .= '<td style="text-align: center;" title="Download File: '.$fileName.'"><a href="'.SITE_URL.'/docs/Uploaded Files/'.$fileName.'"><img src="images/'.$fileIcon.'" style="border: none;" alt="Download File: '.$fileName.'" /></a></td>';
				$fileString .= '<td style="vertical-align: top;">'.$program.' ['.$county.']</td>';		
				$fileString .= '<td style="vertical-align: top;">'.$fileNotes.'</td>';
				$fileString .= '<td>'.$dateUpload.'</td>';
			$fileString .= '</tr>';
	
			$i++;
		} // End While
		$fileString .= '</table>';
	} // End if ($rows>0)

	return $fileString;	
}

function deleteFile($fID) {
	global $dbname, $db, $db_selected;

	// Get file information
	$sql = "SELECT * from casa_uploads WHERE FID = '$fID'";
	$result = mysql_db_query($dbname,$sql);		
	$row = mysql_fetch_assoc($result);

	$fileName = ROOT_DIR.'docs/Uploaded Files/'.$row[FileName];
	// Delete file	
	@unlink($fileName);

	// Delete file information
	$sql = "DELETE from casa_uploads WHERE FID = '$fID'";
	$result = mysql_db_query($dbname,$sql);	

	return $fID;
}
?>